package com.ddstation.chart.util;

import com.ddstation.common.util.DateUtil;
import java.text.SimpleDateFormat;
import java.util.Calendar;

public class CvnDateUtil {

    public static void main(String[] args) {

    }

    // 根据首页选的区分，转换成查询区间
    public static String[] cvnDateRange(int datePatten){
        String[] dateRange = new String[2];
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Calendar cal = Calendar.getInstance();
        // 0：今日  1：本周)
        switch (datePatten) {
            //0：今日
            case 0:
                dateRange[0] = sdf.format(cal.getTime());
                dateRange[1] = sdf.format(cal.getTime());
                return dateRange;
            case 1://本周
                dateRange[1] = sdf.format(cal.getTime());
                cal.add(Calendar.DAY_OF_WEEK, -6);
                dateRange[0] = sdf.format(cal.getTime());
                return dateRange;
            case 2:// 本月
                SimpleDateFormat sdf1 = new SimpleDateFormat("yyyyMM");
                String queryYm = sdf1.format(cal.getTime());
                return DateUtil.getBeginEndDate(queryYm);//根据年月获得 月初、月末日期
            case 3:// 近一月
                //sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                dateRange[1] = sdf.format(cal.getTimeInMillis());
                cal.add(Calendar.DAY_OF_MONTH, -30);
                dateRange[0] = sdf.format(cal.getTimeInMillis());
                return dateRange;//根据年月获得 月初、月末日期
            default:
                break;
        }
        return dateRange;
    }

}
